/**
 * Start presenting an arithmetic exercise  
 * 
 * @author Gerd Wagner
 * 
 * @param {ArithmeticExercise} ae  An arithmetic exercise.
 */
oa.ctrl.startExercise = function( ae) {
  if (ae.renderingForm.isApplicableTo( ae.problemType)) {
    oa.currentExercise = ae;
    oa.view.fillExerciseHeader( ae);
    if (oa.learner.firstName === "Lenz" && oa.correctAnswerCounter >= 10) { oa.view.toggleTito(); }
    if (oa.currentExercise.renderingForm.helpText) { oa.view.showHelpButton();} 
    else { oa.view.hideHelpButton();}
    ae.isBasicExercise = ae.problemType.isBasicProblemType();
    if (ae.isBasicExercise) { ae.generateProblemPool(); }
    switch (ae.renderingForm.mode) {
    case RenderingModeEL.individually:
      oa.currentProblem = (ae.isBasicExercise) ? 
          ae.generateBasicProblem() : ae.problemType.generateProblem();
      if (!oa.currentProblem) {
        console.log("Flawed problem type: %o", ae.problemType);
        oa.ctrl.continueCurrentLearningUnit();;
      } else {
        if (!ae.renderingForm.noEvaluation) oa.learningUnitProblemCounter += 1;
        oa.exerciseProblemCounter = 1;
      }
      break;
    case RenderingModeEL.enbloc: 
      oa.currentProblems = (ae.isBasicExercise) ? 
          ae.generateBasicProblems( ae.numberOfProblems) : ae.problemType.generateProblems( ae.numberOfProblems);
      if (!ae.renderingForm.noEvaluation) oa.learningUnitProblemCounter += ae.numberOfProblems;
      oa.exerciseProblemCounter = 1;
      break;      
    }
    oa.attemptCounter = 1;
    oa.view.render();
    oa.view.fill();
    if (ae.renderingForm.noEvaluation) {
      oa.view.hideEvaluationInfo();
    } else {
      oa.view.showEvaluationInfo();      
    }
  }
  else {
    console.log("Rendering form "+ ae.renderingForm.name +" is not applicable to problem type "+ ae.problemType.name);
    if (ae.renderingForm.mode === RenderingModeEL.individually) { 
      oa.ctrl.continueCurrentExercise();
    } else {
      oa.ctrl.continueCurrentLearningUnit();
    }
  }
};
